/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sistemas.sisgear.controladores;

import com.sistemas.sisgear.dao.UsuarioFacade;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;

/**
 *
 * @author Jorge
 */
@Named(value = "loginControlador")
@SessionScoped
public class LoginControlador implements Serializable {
    @EJB
    private UsuarioFacade usuarioFacade;

    private String username;
    private String password;
    /**
     * Creates a new instance of LoginControlador
     */
    public LoginControlador() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    public String loginControl(){
        if(usuarioFacade.loginControl(username, password)){
            return "/admin/welcome_admin.xhtml?faces-redirect=true";
        }
        RequestContext.getCurrentInstance().update("growl");
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error","Username or Password invalid!!!"));
        return "";
    }
    
}
